using UnityEngine;

public class PlayerStateBehavior_JumpBall : AbstractPlayerStateBehavior
{
	public static PlayerStateBehavior_JumpBall instance;

	private PlayerStateBehavior_JumpBall()
	{
	}

	public static PlayerStateBehavior_JumpBall getInstance()
	{
		if (instance == null)
		{
			instance = new PlayerStateBehavior_JumpBall();
		}
		return instance;
	}

	public override void enter(Player owner)
	{
		base.enter(owner);
		owner.playAnimation(AnimationName.player_jumpball, 1f, 0.8f);
		if (owner.getOffenseDirection() == OffenseDirection.LEFT)
		{
			owner.setMirrorAnimation();
		}
		else
		{
			owner.setNormalAnimation();
		}
		owner.LookAt(MathHelper.setY(Instance<CameraController>.instance.getCameraPos(), 0f));
		if ((true) && owner.teamType == TeamType.USER)
		{
			Instance<UIGame>.instance.isLockPauseBtn = false;
			Instance<UIGame>.instance.isLockPassBtn = true;
			Instance<UIGame>.instance.isLockShootBtn = true;
			Instance<UIGame>.instance.isLockJoystick = true;
		}
	}

	public override void fixedUpdate(Player owner)
	{
		base.fixedUpdate(owner);
		if (false)
		{
			if (owner.teamType == TeamType.COMPUTER)
			{
				return;
			}
			if (!Instance<Ball>.instance.isJumpBalled)
			{
				Vector3 position = Instance<Ball>.instance.getPosition();
				if (position.y > 2.8f)
				{
					Instance<Court>.instance.isUserGetJumpBall = (owner.teamType == TeamType.USER);
					Instance<Ball>.instance.isJumpBalled = true;
					Instance<Ball>.instance.GetComponent<Rigidbody>().velocity = Vector3.zero;
					Instance<Ball>.instance.GetComponent<Rigidbody>().AddForce(MathHelper.setY(owner.team.getPlayer(PlayerType.POINTGUARD).getPosition(), -0.5f), ForceMode.Impulse);
					owner.team.getPlayer(PlayerType.POINTGUARD).AI.do_chase_ball();
					Instance<AudioController>.instance.play(AudioType.Sound_cheer_score);
					Instance<AudioController>.instance.play(AudioType.Sound_catch);
				}
			}
			if (!owner.IsPlayingAnimation() && !Instance<Ball>.instance.isJumpBalled)
			{
				Vector3 position2 = Instance<Ball>.instance.getPosition();
				if (position2.y < 1f)
				{
					Instance<Court>.instance.isUserGetJumpBall = (owner.teamType == TeamType.USER);
					Instance<Ball>.instance.isJumpBalled = true;
					Instance<Ball>.instance.GetComponent<Rigidbody>().velocity = Vector3.zero;
					Instance<Ball>.instance.GetComponent<Rigidbody>().AddForce(MathHelper.setY(owner.team.getPlayer(PlayerType.POINTGUARD).getPosition(), 1f), ForceMode.Impulse);
					owner.team.getPlayer(PlayerType.POINTGUARD).AI.do_chase_ball();
					Instance<AudioController>.instance.play(AudioType.Sound_cheer_score);
					Instance<AudioController>.instance.play(AudioType.Sound_catch);
				}
			}
		}
		else
		{
			if (Instance<Ball>.instance.isJumpBalled)
			{
				return;
			}
			Vector3 position3 = Instance<Ball>.instance.getPosition();
			if (position3.y > 2.8f)
			{
				Vector3 position4 = owner.trans_LeftHand.position;
				float y = position4.y;
				Vector3 position5 = Instance<Ball>.instance.getPosition();
				if (y - position5.y > -0.1f && MathHelper.getSqrDistance(owner.trans_LeftHand.position, Instance<Ball>.instance.getPosition()) < 0.9f)
				{
					Instance<Court>.instance.isUserGetJumpBall = (owner.teamType == TeamType.USER);
					Instance<Ball>.instance.isJumpBalled = true;
					Instance<Ball>.instance.GetComponent<Rigidbody>().velocity = Vector3.zero;
					Instance<Ball>.instance.GetComponent<Rigidbody>().AddForce(MathHelper.setY(owner.team.getPlayer(PlayerType.POINTGUARD).getPosition(), -0.6f), ForceMode.Impulse);
					owner.team.getPlayer(PlayerType.POINTGUARD).AI.do_chase_ball();
					Instance<AudioController>.instance.play(AudioType.Sound_cheer_score);
					Instance<AudioController>.instance.play(AudioType.Sound_catch);
				}
			}
		}
	}

	public override void exit(Player owner)
	{
		base.exit(owner);
		owner.setNormalAnimation();
		if (!owner.paraPlayer.isInState(getInstance()))
		{
			Instance<Ball>.instance.isJumpBalled = true;
		}
		if (true)
		{
			Instance<UIGame>.instance.isLockPauseBtn = false;
			Instance<UIGame>.instance.isLockPassBtn = false;
			Instance<UIGame>.instance.isLockShootBtn = false;
			Instance<UIGame>.instance.isLockJoystick = false;
		}
	}
}
